import { Form, Radio } from "antd";
import RadioGroup from "antd/lib/radio/group";
import moment from "moment";
import * as React from "react";
const { Item } = Form;

export function OrderTime(setFieldsValue:(obj: Object, callback?: Function)=> void) {
  return (
    <Item label="订单时长">
      <RadioGroup
        onChange={v => {
          const val = v.target.value;
          // 默认的会在当前时间加上300秒,也就是赠送用户5分钟
          const giveTime = 300;
          // 当前时间戳
          let timestamp = new Date().getTime() / 1000 + giveTime;
          const ONE_HOUR = 3600;
          const ONE_DAY = 86400;
          const ONE_MONTH = 2592000;
          const ONE_YEAR = 31536000;
          switch (val) {
            case 0: {
              timestamp += ONE_HOUR;
              break;
            }
            case 1: {
              timestamp += ONE_DAY;
              break;
            }
            case 2: {
              timestamp += ONE_MONTH;
              break;
            }
            case 3: {
              timestamp += ONE_YEAR;
              break;
            }
          }
          const expiryTime = moment(timestamp, "X");
          setFieldsValue({ expiryTime });
        }}
      >
        <Radio key={0} value={0}>
          1小时
        </Radio>
        <Radio key={1} value={1}>
          1天
        </Radio>
        <Radio key={2} value={2}>
          1个月
        </Radio>
        <Radio key={3} value={3}>
          1年
        </Radio>
      </RadioGroup>
    </Item>
  );
}
